<?php
class StudentFromAction extends CommonAction {
	
	/**
	 * 查询(non-PHPdoc)
	 * @see CommonAction::read()
	 */
	public function read() {
		$map = "  1=1 ";
		if(!empty($_POST['XS_XX'])) {
			$map = $map." and student.XS_XX = '".$_POST['XS_XX']."'";
		}
		if(!empty($_POST['XS_NJ'])) {
			$map = $map." and student.XS_NJ = '".$_POST['XS_NJ']."'";
		}
		if(!empty($_POST['XS_BJ'])) {
			$map = $map." and student.XS_BJ = '".$_POST['XS_BJ']."'";
		}
		$map = $map." and student.XS_ZT = 'xszt1' ";
		
		$xqid =  $_SESSION['XqFilterString'] ;//获取用户当前拥有校区权限
		if(!empty($xqid)){
			$map = $map." and student.XS_XQ in (".$xqid.") ";
		}		
		
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$Student = M ( "Student" );

		$arrNum = $Student->query("select count(*) as num from smis_student student where 1=1 and" . $map);
		$row = $arrNum[0]['num'];
		$total = $row;	
		
// 		import("ORG.Util.Page");
// 		$logsPa = new Page($total,$rowsnum);
		$studentList = array ();
		$studentList = $Student->table('smis_student student')
								->join('smis_dictionary_list dictionary  on student.XS_NJ = dictionary.ITEM_KEY')
								->join('smis_dictionary_list dictionary1 on student.XS_XX = dictionary1.ITEM_KEY')
								->join('smis_dictionary_list dictionary2 on student.XS_BJ = dictionary2.ITEM_KEY')
								->where($map)
								->field('student.*,dictionary.ITEM_VALUE as NJ,dictionary1.ITEM_VALUE as XX,dictionary2.ITEM_VALUE as BJ')
								->order('student.id desc' )
								->page($pagenum,$rowsnum)->select();
		
		$resultJson = json_encode($studentList);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
	}
	
	/**
	 * 查询(non-PHPdoc)
	 * @see CommonAction::read()
	public function read() {
		if(!empty($_POST['XS_XM'])) {	
			$map['XS_XM'] = array('like',"%".$_POST['XS_XM']."%");
		}
		if(!empty($_POST['XS_PY'])) {
			$map['XS_PY'] = array('like',"%".$_POST['XS_PY']."%");
		}		
		if(!empty($_POST['XS_XH'])) {
			$map['XS_XH'] = array('like',"%".$_POST['XS_XH']."%");
		}
		if(!empty($_POST['XS_XX'])) {
			$map['XS_XX'] = $_POST['XS_XX'];
		}
		$begin = $_POST['XS_CSRQ_BEGIN'];
		if((!empty($_POST['XS_CSRQ_BEGIN']))&&(!empty($_POST['XS_CSRQ_END']))) {
			$map['XS_CSRQ'] = $map['id']  = array('between',array($_POST['XS_CSRQ_BEGIN'],$_POST['XS_CSRQ_END']));
		}
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$Student = M ( "Student" );
		$fix = C( "DB_PREFIX" );
		
		$total = $Student->where($map)->count (); // 计算总数	
		import("ORG.Util.Page");// 导入分页类
		$studentList = array ();
		$studentList = $Student->where($map)->limit ( ($pagenum - 1) * $rowsnum . ',' . $rowsnum )->order ( 'id asc' )->select ();
		$resultJson = json_encode($studentList);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中		
		echo $json;
	}	 */
	
	/**
	 * 获取所有学校列表
	 */
	public function schoolList() {
		$type = $_GET["type"];
		$DictionaryList = M ( "DictionaryList" );
		$schoolList = array();
		$schoolList = $DictionaryList->where('ITEM_FLID = ' . $type)->select();
		$resultJson = json_encode($schoolList);
		$resultJson = substr($resultJson, 1, strlen($resultJson));
		$resultJson = '[{"ITEM_KEY":"0","ITEM_VALUE":"请选择","selected":true},' . $resultJson;
		//$schools = '[{"id":0,"text":"请选择","selected":true},{"id":1,"text":"华师一附中"},{"id":2,"text":"关山中学"},{"id":3,"text":"武汉三中"}]';
		echo $resultJson;
	}
	
	
	/**
	 * 获取字典表数据
	 */
// 	public function getDictList(){
// 		// $flValue = $_REQUEST ['flValue'];
// 		$flValue = $_GET["type"];
// 		$dicList = D( "DictionaryList" );
// 		$dictList = $dicList->getDictList($flValue);
// 		$resultJson = json_encode($dictList);
// 		$resultJson = substr($resultJson, 1, strlen($resultJson));
// 		$resultJson = '[{"ITEM_KEY":"0","text":"请选择","selected":true},' . $resultJson;
// 		echo $resultJson;
// 	}
	
	/**
	 * 获取推荐人
	 */
	public function getTJR() {
		$User = M ( "User" );
		$userList = array ();
		$userList = $User->order ( 'id asc' )->select ();
		$resultJson = json_encode($userList);
		$resultJson = substr($resultJson, 1, strlen($resultJson));
		$resultJson = '[{"account":"0","nickname":"请选择","selected":true},' . $resultJson;
		echo $resultJson;
	}
}
?>
